********************************************************************************
******************************  TABLE A19  *************************************
**************  Converting Task Performance to Influence  **********************
********************************************************************************

clear
//cd "C:/Users/ganth/Dropbox/StrengthInNumbersReplicationPackage/replicable/table_a19"


*ssc install outreg2
*ssc install estout

********************************************************************************

**Study 1 Analysis
use "table_a19_dataset_1.dta", clear

rename group_id_fall group_id

keep if fall_condition==1 | fall_condition==3
gen condition_2f = (fall_condition==1)
g maleMajority = fall_condition==1
la var maleMajority "Majority male group"
la var total_labavg "Task Errors"
g total_labavgXfemale = total_labavg*female
la var total_labavgXfemale "Female * Task Errors"

eststo clear
eststo: reg minfl_votes_labavg total_labavg female total_labavgXfemale if maleMajority, cluster(group_id)
estadd ysumm
eststo: reg minfl_votes_labavg total_labavg female total_labavgXfemale if !maleMajority, cluster(group_id)
estadd ysumm
	
**Study 2 Analysis
use "table_a19_dataset_2.dta", clear

keep if all_female == 0

g maleMajority = condition_2f
la var maleMajority "Majority male group"
la var total_labavg "Task Errors"
g total_labavgXfemale = total_labavg*female
la var total_labavgXfemale "Female * Task Errors"

eststo: reg minfl_votes_r1 total_labavg female total_labavgXfemale if maleMajority, cluster(group_id)
	estadd ysumm
eststo: reg minfl_votes_r1 total_labavg female total_labavgXfemale if !maleMajority, cluster(group_id)
	estadd ysumm
	

**Combined Analysis
use "table_a19_dataset_1.dta", clear

rename group_id_fall group_id

keep if fall_condition==1 | fall_condition==3
gen condition_2f = (fall_condition==1)
drop fall_condition

append using "table_a19_dataset_2.dta"
g maleMajority = condition_2f
la var maleMajority "Majority male group"
drop if study == 2 & all_female==1

replace minfl_votes_labavg = minfl_votes_r1 if study==2
drop minfl_votes_r1

la var female "Female"

la var total_labavg "Task Errors"
g total_labavgXfemale = total_labavg*female
la var total_labavgXfemale "Female \times Task Errors"


eststo: reg minfl_votes_labavg  total_labavg female total_labavgXfemale if maleMajority, cluster(group_id)
	estadd ysumm
eststo: reg minfl_votes_labavg  total_labavg female total_labavgXfemale if !maleMajority, cluster(group_id)
	estadd ysumm
	

esttab _all using "table_a19.tex", style(tex) ///
 stats(N r2 ymean ysd, fmt( %9.0g %9.2f  %9.2f %9.2f) ///
labels("\$N$" "\$R^2$" "Mean of outcome" "St. dev. of outcome")) label replace ///
keep( total_labavg female total_labavgXfemale) ///
star( * .1 ** .05 *** .01) b(%9.3f) se(%9.3f) nogaps  ///
mgroups("Study 1" "Study 2" "Studies 1 + 2", pattern(1 0 1 0 1 0) span prefix(\multicolumn{@span}{c}{) suffix(}) erepeat(\cmidrule(lr){@span})) ///
mtitles("\makecell{(1)\\Majority Male\\Group}" "\makecell{(2)\\Majority Female\\Group}" "\makecell{(3)\\Majority Male\\Group}" "\makecell{(4)\\Majority Female\\Group}" "\makecell{(5)\\Majority Male\\Group}" "\makecell{(6)\\Majority Female\\Group}") ///
nonotes nonum addnotes("\begin{minipage}{`linewidth'\linewidth} \footnotesize \smallskip \textbf{Note:} Table presents individual-level analysis. The dependent variable is the individual's average number of influence votes. Heteroskedasticity-robust group-clustered standard errors are reported in parentheses. Significance levels are indicated by $*$ $<.1$, ** $<.05$,  *** $<.01$.   \end{minipage}" )

	
clear
